package io.renren.modules.offer.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.offer.entity.OfferEntity;
import io.renren.modules.offer.service.OfferService;
import io.renren.common.utils.PageUtils;


/**
 * 
 *
 * @author haijun.zhang
 * @email haijun917@qq.com
 * @date 2018-08-05 00:43:36
 */
@RestController
@RequestMapping("offer/offer")
public class OfferController {
    @Autowired
    private OfferService offerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("offer:offer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = offerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("offer:offer:info")
    public R info(@PathVariable("id") Long id){
        OfferEntity offer = offerService.selectById(id);

        return R.ok().put("offer", offer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("offer:offer:save")
    public R save(@RequestBody OfferEntity offer){
        offerService.insert(offer);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("offer:offer:update")
    public R update(@RequestBody OfferEntity offer){
        ValidatorUtils.validateEntity(offer);
        offerService.updateAllColumnById(offer);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("offer:offer:delete")
    public R delete(@RequestBody Long[] ids){
        offerService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
